home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MacOberon 4.10a / Mac Oberon / Oberon2.Report.Text < prev    next >
Encoding:
Text File  |  1994-09-02  |  67.3 KB  |  75 lines  |  [TEXT/.Ob4]

  1. eter is of type PTR, the actual parameter may be of any pointer type.
  2.     The procedures contained in module SYSTEM are listed in the following tables. Most of them correspond to single instructions compiled as in-line code. For details, the reader is referred to the processor manual. v stands for a variable, x, y, a, and n for expressions, and T for a type.
  3.  
  4. Function procedures
  5.  
  6. Name    Argument types    Result type    Function
  7.  
  8. ADR(v)    any    LONGINT    address of variable v
  9. BIT(a, n)    a: LONGINT    BOOLEAN    bit n of Mem[a]
  10.     n: integer
  11. CC(n)    integer constant    BOOLEAN    condition n (0 <= n <= 15)
  12. LSH(x, n)    x: integer, CHAR, BYTE    type of x    logical shift
  13.     n: integer
  14. ROT(x, n)    x: integer, CHAR, BYTE    type of x    rotation
  15.     n: integer
  16. VAL(T, x)    T, x: any type    T    x interpreted as of type T
  17.  
  18. Proper procedures
  19.  
  20. Name    Argument types    Function
  21.  
  22. GET(a, v)    a: LONGINT; v: any basic type,    v := Mem[a]
  23.     pointer, procedure type
  24. PUT(a, x)    a: LONGINT; x: any basic type,    Mem[a] := x
  25.     pointer, procedure type
  26. GETREG(n, v)    n: integer constant; v: any basic type,    v := Register n
  27.     pointer, procedure type
  28. PUTREG(n, x)    n: integer constant; x: any basic type,    Register n := x
  29.     pointer, procedure type
  30. MOVE(a0, a1, n)    a0, a1: LONGINT; n: integer    Mem[a1.. a1+n-1] := Mem[a0.. a0+n-1]
  31. NEW(v, n)    v: any pointer; n: integer    allocate storage block of n bytes
  32.         assign its address to v
  33.  
  34. Appendix D: The Oberon Environment
  35.  
  36. Oberon-2 programs usually run in an environment that provides command activation, garbage collection, dynamic loading of modules, and certain run time data structures. Although not part of the language, this environment contributes to the power of Oberon-2 and is to some degree implied by the language definition. Appendix D describes the essential features of a typical Oberon environment and provides implementation hints. More details can be found in [1], [2], and [3].
  37.  
  38.  
  39. D1. Commands
  40.  
  41. A command is any parameterless procedure P that is exported from a module M. It is denoted by M.P and can be activated under this name from the shell of the operating system. In Oberon, a user invokes commands instead of programs or modules. This gives him a finer grain of control and allows modules with multiple entry points. When a command M.P is invoked, the module M is dynamically loaded unless it is already in memory (see D2) and the procedure P is executed. When P terminates, M remains loaded. All global variables and data structures that can be reached from global pointer variables in M retain their values. When P (or another command of M) is invoked again, it may continue to use these values.
  42.     The following module demonstrates the use of commands. It implements an abstract data structure Counter that encapsulates a counter variable and provides commands to increment and print its value.
  43.  
  44. MODULE Counter;
  45.     IMPORT Texts, Oberon;
  46.  
  47.     VAR
  48.         counter: LONGINT;
  49.         w: Texts.Writer;
  50.  
  51.     PROCEDURE Add*;   (* takes a numeric argument from the command line *)
  52.         VAR s: Texts.Scanner;
  53.     BEGIN 
  54.         Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
  55.         Texts.Scan(s);
  56.         IF s.class = Texts.Int THEN INC(counter, s.i) END
  57.     END Add;
  58.  
  59.     PROCEDURE Write*;
  60.     BEGIN
  61.         Texts.WriteInt(w, counter, 5); Texts.WriteLn(w);
  62.         Texts.Append(Oberon.Log, w.buf)
  63.     END Write;
  64.  
  65. BEGIN counter := 0; Texts.OpenWriter(w)
  66. END Counter.
  67.  
  68. The user may execute the following two commands:
  69.  
  70. Counter.Add   n     adds the value n to the variable counter
  71. Counter.Write     writes the current value of counter to the screen
  72.  
  73. Since commands are parameterless they have to get their arguments from the operating system. In general, commands are free to take arguments from everywhere (e.g. from the text following the command, from the most recent selection, or from a marked viewer). The command Add uses a scanner (a data type provided by the Oberon system) to read the value that follows it on the command line.
  74.     When Counter.Add is invoked for the first time, the module Counter is loaded and its body is executed. Every call of Counter.Add n increments the variable counter by n. Every call of Counter.Write writes the current value of counter to the screen.